package com.daxiong.hfs.bean;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.daxiong.hfs.R;

public class CustomListBean extends BaseAdapter {

	static class ViewHolder {
		TextView chineseName;
	}

	private List<ProductBean> resultList;

	private LayoutInflater layoutInflater;

	public CustomListBean( //
			final Context context, //
			final List<ProductBean> productBeanList //
	) {
		this.resultList = productBeanList;
		layoutInflater = LayoutInflater.from(context);
	}

	public int getCount() {
		return resultList.size();
	}

	public Object getItem(final int position) {
		return resultList.get(position);
	}

	public long getItemId(final int position) {
		return position;
	}

	public View getView( //
			final int position, //
			View convertView, //
			final ViewGroup parent //
	) {
		ViewHolder viewHolder;

		if (convertView == null) {
			convertView = //
			layoutInflater.inflate(R.layout.list_row_layout, null);

			viewHolder = new ViewHolder();

			viewHolder.chineseName = //
			(TextView) convertView.findViewById(R.id.chinese_name);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		final CharSequence charSequence = //
		resultList.get(position).getChineseName();

		viewHolder.chineseName.setText(charSequence);

		return convertView;
	}

}
